home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / svgacc20.arj / SVGADEM1.C < prev    next >
C/C++ Source or Header  |  1994-03-11  |  24KB  |  1,094 lines

  1. /****************************************************************************
  2.      
  3.       'SVGACC' A Super Vga Graphics Library for use with Microsoft and
  4.       Borland C/C++
  5.       Copyright 1993-1994 by Stephen L. Balkum and Daniel A. Sill
  6.  
  7.       GIF and 'Graphics Intechange Format' are trademarks (tm) of
  8.       Compuserve, Incorporated, an H&R Block Company.
  9.  
  10.     **************** UNREGISTERD SHAREWARE VERSION ***********************
  11.     * FOR EVUALATION ONLY. NOT FOR RESALE IN ANY FORM. SOFTWARE WRITTEN  *
  12.     * USING THIS UNREGISTERED SHAREWARE GRAPHICS LIBRARY MAY NOT BY SOLD *
  13.     * OR USED FOR ANY PURPOSE OTHER THAN THE EVUALTION OF THIS LIBRARY.  *
  14.     **********************************************************************
  15.  
  16.     **************** NO WARRANTIES AND NO LIABILITY **********************
  17.     * Stephen L. Balkum and Daniel A. Sill provide no warranties, either *
  18.     * expressed or implied, of merchantability, or fitness, for a        *
  19.     * particular use or purpose of this SOFTWARE and documentation.      *
  20.     * In no event shall Stephen L. Balkum or Daniel A. Sill be held      *
  21.     * liable for any damages resulting from the use or misuse of the     * 
  22.     * SOFTWARE and documentation.                                        *
  23.     **********************************************************************
  24.  
  25.     ************** U.S. GOVERNMENT RESTRICTED RIGHTS *********************
  26.     * Use, duplication, or disclosure of the SOFTWARE and documentation  *
  27.     * by the U.S. Government is subject to the restictions as set forth  *
  28.     * in subparagraph (c)(1)(ii) of the Rights in Technical Data and     *
  29.     * Computer Software cluse at DFARS 252.227-7013.                     *
  30.     * Contractor/manufacturer is Stephen L. Balkum and Daniel A. Sill,   *
  31.     * P.O. Box 7704, Austin, Texas 78713-7704                            *
  32.     **********************************************************************
  33.  
  34.     **********************************************************************
  35.     * By using this SOFTWARE or documentation, you agree to the above    *
  36.     * terms and conditions.                                              *
  37.     **********************************************************************
  38.  
  39.  ***************************************************************************/
  40.  
  41. #define MODULE
  42.  
  43. #include <stdio.h>
  44. #include <conio.h>
  45. #include <stdlib.h>
  46. #include <malloc.h>
  47. #include <string.h>
  48. #include <math.h>
  49.  
  50. #include "svgacc.h"
  51.  
  52. #include "svgademo.h"
  53.  
  54. #define randnum(size) (rand() % (int)(size))
  55.  
  56. /***********
  57.  * DOBLOCK *
  58.  ***********/
  59.  
  60. char doblock(void)
  61. {
  62.     int i, colr;
  63.     int xinc, yinc, x1, y1, x2, y2;
  64.     int cntx, cnty;
  65.     char ret;
  66.     char title[TITLEN];
  67.     char buf[TITLEN];
  68.     RasterBlock far *gfxblk;
  69.     RasterBlock far *gfxblk2;
  70.     RasterBlock far *spritebkgnd;
  71.  
  72.     /*
  73.      * Set up the Title
  74.      */
  75.     sprintf(title,"DEMO 5: Block function and Sprites");
  76.     palset(pal,0,255);
  77.  
  78.     /*
  79.      * Show Block Get (draw some circles and "get a chunk of them")
  80.      */
  81.  
  82.     fillscreen(0);
  83.     setview(0,0,maxx,maxy);
  84.     drwstring(1,7,0,title,10,0);
  85.     sprintf(buf,"blkget(x1,y1,x2,y2,GfxBlock);");
  86.     drwstring(1,7,0,buf,10,16);
  87.     colr = 16;
  88.     for(i=0;i<=maxx/2;i++) {
  89.         drwcircle(1,colr,maxx/4+i,maxy/2,maxy/5);
  90.         colr+=2;
  91.         if(colr>255)
  92.             colr = 16;
  93.     }
  94.     
  95.     xinc = maxx/20;
  96.     yinc = maxy/20;
  97.     x1 = maxx/2-xinc;
  98.     y1 = maxy/2-yinc;
  99.     x2 = maxx/2+xinc;
  100.     y2 = maxy/2+yinc;
  101.     i = (x2-x1+1)*(y2-y1+1)+4;
  102.     gfxblk = _fmalloc(i);
  103.     if (!gfxblk) {
  104.         restext();
  105.         printf("ERROR: Allocating memory for gfxblk: %d bytes\n",i);
  106.         exit(1);
  107.     }
  108.     drwbox(1,0,x1,y1,x2,y2);
  109.     blkget(x1,y1,x2,y2,gfxblk);
  110.     
  111.     ret = getkey();
  112.     if ((ret == 's') || (ret == 'q')) {
  113.         fillscreen(0);
  114.         _ffree(gfxblk);
  115.         return(ret);
  116.     }
  117.  
  118.     /*
  119.      * Show Block Rotate and Sprite Stuff
  120.      */
  121.     drwstring(1,7,0,title,10,0);
  122.     sprintf(buf,"blkrotate(angle,backfill,GfxBlockSrc,GfxBlockDst);");
  123.     drwstring(1,7,0,buf,10,16);
  124.     sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
  125.     drwstring(1,7,0,buf,10,32);
  126.     sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
  127.     drwstring(1,7,0,buf,10,48);
  128.     cntx = (x2-x1) / 2 + x1;
  129.     cnty = (y2-y1) / 2 + y1;
  130.     fillarea(x1+2,y1+2,0,0);
  131.     i = blkrotatesize(45,gfxblk);
  132.     spritebkgnd = _fmalloc(i);
  133.     if (!spritebkgnd) {
  134.         restext();
  135.         printf("ERROR: Allocating memory for spritebkgnd: %d bytes\n",i);
  136.         exit(1);
  137.     }
  138.     gfxblk2 = _fmalloc(i);
  139.     if (!gfxblk2) {
  140.         restext();
  141.         printf("ERROR: Allocating memory for gfxblk2: %d bytes\n",i);
  142.         exit(1);
  143.     }
  144.     blkget(x1,y1,x2,y2,spritebkgnd);
  145.     setview(0,64,maxx,maxy);
  146.  
  147.     for(i=0;i<=360;i+=4) {
  148.         blkrotate(i,1,gfxblk,gfxblk2);
  149.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  150.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  151.         sdelay(4);
  152.     }
  153.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  154.     blkput(SET,x1,y1,gfxblk);
  155.  
  156.     setview(0,0,maxx,maxy);
  157.     ret = getkey();
  158.     if ((ret == 's') || (ret == 'q')) {
  159.         fillscreen(0);
  160.         palset(pal,16,255);
  161.         _ffree(gfxblk);
  162.         _ffree(gfxblk2);
  163.         _ffree(spritebkgnd);
  164.         return(ret);
  165.     }
  166.  
  167.     /*
  168.      * Show Block Resize and Sprite Stuff
  169.      */
  170.     drwstring(1,7,0,title,10,0);
  171.     sprintf(buf,"blkresize(Width,Height,GfxBlockSrc,GfxBlockDst);");
  172.     drwstring(1,7,0,buf,10,16);
  173.     sprintf(buf,"spritegap(transcolor,x,y,SpriteArray,BkGndArray);");
  174.     drwstring(1,7,0,buf,10,32);
  175.     sprintf(buf,"spriteput(transcolor,x,y,SpriteArray);");
  176.     drwstring(1,7,0,buf,10,48);
  177.     fillarea(x1+2,y1+2,0,0);
  178.     blkget(x1,y1,x2,y2,spritebkgnd);
  179.     setview(0,64,maxx,maxy);
  180.  
  181.     i = (x2-x1+1+xinc)*(y2-y1+1+xinc)+4;
  182.  
  183.     spritebkgnd = _frealloc(spritebkgnd,i);
  184.     if (!spritebkgnd) {
  185.         restext();
  186.         printf("ERROR: reallocating memory for spritebkgnd: %d bytes\n",i);
  187.         exit(1);
  188.     }
  189.  
  190.     gfxblk2 = _frealloc(gfxblk2,i);
  191.     if (!gfxblk2) {
  192.         restext();
  193.         printf("ERROR: reallocating memory for gfxblk2: %d bytes\n",i);
  194.         exit(1);
  195.     }
  196.  
  197.     for(i=0;i<=xinc;i++) {
  198.         blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
  199.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  200.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  201.         sdelay(3);
  202.     }
  203.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  204.  
  205.     for(i=xinc;i>=0;i--) {
  206.         blkresize((gfxblk->width)-i,(gfxblk->height)-i,gfxblk,gfxblk2);
  207.         spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  208.         spritegap(1,cntx-(gfxblk2->width)/2,cnty-(gfxblk2->height)/2,gfxblk2,spritebkgnd);
  209.         sdelay(3);
  210.     }
  211.     spriteput(SET,1,cntx-(spritebkgnd->width)/2,cnty-(spritebkgnd->height)/2,spritebkgnd);
  212.     blkput(SET,x1,y1,gfxblk);
  213.  
  214.     ret = getkey();
  215.     if ((ret == 's') || (ret == 'q')) {
  216.         fillscreen(0);
  217.         palset(pal,16,255);
  218.         setview(0,0,maxx,maxy);
  219.         _ffree(gfxblk);
  220.         _ffree(gfxblk2);
  221.         _ffree(spritebkgnd);
  222.         return(ret);
  223.     }
  224.  
  225.  
  226.     /*
  227.      * Show Block Put (put the "chunks" randomly around the screen)
  228.      */
  229.     setview(0,16,maxx,32);
  230.     fillview(0);
  231.     sprintf(buf,"blkput(mode,x,y,GfxBlock);");
  232.     drwstring(1,7,0,buf,10,16);
  233.     xinc = maxx/10;
  234.     yinc = maxy/10;
  235.     setview(0,32,maxx,maxy);
  236.     for(i=0;i<=maxx/2;i++) {
  237.         x1 = randnum(maxx + xinc) - xinc;
  238.         y1 = randnum(maxy + yinc) - yinc;
  239.         blkput(1,x1,y1,gfxblk);
  240.     }
  241.  
  242.     _ffree(gfxblk);
  243.     _ffree(gfxblk2);
  244.     _ffree(spritebkgnd);
  245.     setview(0,0,maxx,maxy);
  246.     ret = getkey();
  247.     if ((ret == 's') || (ret == 'q')) {
  248.         fillscreen(0);
  249.         return(ret);
  250.     }
  251.  
  252.     return(ret);
  253.     
  254. }
  255.  
  256.  
  257.  
  258. /**********
  259.  * DOCLIP *
  260.  **********/
  261.  
  262. char doclip(void)
  263. {
  264.     struct dcoord {
  265.         int x1;
  266.         int x2;
  267.         int y1;
  268.         int y2;
  269.     };
  270.     
  271.     int i, j, k;
  272.     int xinc, x, y, x1, y1, x2, y2;
  273.     int xsub, radx, rady;
  274.     int wdth, hgth, spcingx, spcingy;
  275.     struct dcoord b[4];
  276.     char ret;
  277.     char title[TITLEN];
  278.     char buf[TITLEN];
  279.     
  280.     /*
  281.      * Set up the Title
  282.      */
  283.     sprintf(title,"DEMO 2: Clipping capability");
  284.     palset(pal,0,255);
  285.  
  286.     /*
  287.      * Set up the windows
  288.      */
  289.  
  290.     fillscreen(0);
  291.     setview(0,0,maxx,maxy);
  292.     drwstring(1,7,0,title,10,0);
  293.     sprintf(buf,"All pimitives automatically clip");
  294.     drwstring(1,7,0,buf,10,16);
  295.  
  296.     wdth = (maxx + 1) * 4 / 9;
  297.     spcingx = ((maxx + 1) - wdth * 2) / 3;
  298.     hgth = (maxy + 1 - 35) * 4 / 9;
  299.     spcingy = ((maxy + 1 - 35) - hgth * 2) / 3;
  300.     xinc = wdth * 3 / 2;
  301.     xsub = wdth / 4;
  302.     
  303.     b[0].x1 = spcingx;
  304.     b[0].x2 = b[0].x1 + wdth;
  305.     b[0].y1 = spcingy + 35;
  306.     b[0].y2 = b[0].y1 + hgth;
  307.  
  308.     b[1].x2 = maxx - spcingx;
  309.     b[1].x1 = b[1].x2 - wdth;
  310.     b[1].y1 = spcingy + 35;
  311.     b[1].y2 = b[1].y1 + hgth;
  312.  
  313.     b[2].x2 = maxx - spcingx;
  314.     b[2].x1 = b[2].x2 - wdth;
  315.     b[2].y2 = maxy - spcingy;
  316.     b[2].y1 = b[2].y2 - hgth;
  317.  
  318.     b[3].x1 = spcingx;
  319.     b[3].x2 = b[3].x1 + wdth;
  320.     b[3].y2 = maxy - spcingy;
  321.     b[3].y1 = b[3].y2 - hgth;
  322.  
  323.     for(i=0;i<4;i++)
  324.         drwbox(1,15,b[i].x1++,b[i].y1++,b[i].x2--,b[i].y2--);
  325.  
  326.     /*
  327.      * Show the clipping
  328.      */
  329.     for(i=0;i<=maxx/6;i++)
  330.         for(j=0;j<4;j++) {
  331.             setview(b[j].x1,b[j].y1,b[j].x2,b[j].y2);
  332.             switch (j) {
  333.                 case 0:
  334.                     for(k=0;k<6;k++) {
  335.                         x = b[j].x1 + randnum(xinc) - xsub;
  336.                         y = b[j].y1 + randnum(xinc) - xsub;
  337.                         drwpoint(1,randnum(16),x,y);
  338.                     }
  339.                     break;
  340.                 case 1:
  341.                     x1 = b[j].x1 + randnum(xinc) - xsub;
  342.                     y1 = b[j].y1 + randnum(xinc) - xsub;
  343.                     x2 = b[j].x1 + randnum(xinc) - xsub;
  344.                     y2 = b[j].y1 + randnum(xinc) - xsub;
  345.                     drwline(1,randnum(16),x1,y1,x2,y2);
  346.                     break;
  347.                 case 2:
  348.                     x = b[j].x1 + randnum(xinc) - xsub;
  349.                     y = b[j].y1 + randnum(xinc) - xsub;
  350.                     radx = randnum(wdth) / 2;
  351.                     drwcircle(1,randnum(16),x,y,radx);
  352.                     break;
  353.                 case 3:
  354.                     x = b[j].x1 + randnum(xinc) - xsub;
  355.                     y = b[j].y1 + randnum(xinc) - xsub;
  356.                     radx = randnum(wdth) / 2;
  357.                     rady = randnum(wdth) / 2;
  358.                     drwellipse(1,randnum(16),x,y,radx,rady);
  359.                     break;
  360.             }
  361.         }
  362.  
  363.     setview(0,0,maxx,maxy);
  364.  
  365.     ret = getkey();
  366.  
  367.     return(ret);
  368.     
  369. }
  370.  
  371. /**********
  372.  * DOFILL *
  373.  **********/
  374.  
  375. char dofill(void)
  376. {
  377.     struct dcoord {
  378.         int x1;
  379.         int x2;
  380.         int y1;
  381.         int y2;
  382.     };
  383.     
  384.     int i, colr;
  385.     int x, y;
  386.     int radx, rady;
  387.     int wdth, hgth, spcingx, spcingy;
  388.     struct dcoord b[4];
  389.     char ret;
  390.     char title[TITLEN];
  391.     char buf[TITLEN];
  392.     
  393.     /*
  394.      * Set up the Title
  395.      */
  396.     sprintf(title,"DEMO 3: Filling functions");
  397.     palset(pal,0,255);
  398.  
  399.     /*
  400.      * Set up the windows
  401.      */
  402.  
  403.     fillscreen(10);
  404.     setview(0,0,maxx,maxy);
  405.     drwstring(1,7,0,title,10,0);
  406.     sprintf(buf,"fillscreen(color);");
  407.     drwstring(1,7,0,buf,10,16);
  408.  
  409.     ret = getkey();
  410.     if ((ret == 's') || (ret == 'q'))
  411.         return(ret);
  412.     
  413.     /*
  414.      * Set up windows and show viewport fill
  415.      */
  416.     fillscreen(0);
  417.     drwstring(1,7,0,title,10,0);
  418.     sprintf(buf,"fillview(color);");
  419.     drwstring(1,7,0,buf,10,16);
  420.     
  421.     wdth = (maxx + 1) * 4 / 9;
  422.     spcingx = ((maxx + 1) - wdth * 2) / 3;
  423.     hgth = (maxy + 1 - 35) * 4 / 9;
  424.     spcingy = ((maxy + 1 - 35) - hgth * 2) / 3;
  425.  
  426.     b[0].x1 = spcingx;
  427.     b[0].x2 = b[0].x1 + wdth;
  428.     b[0].y1 = spcingy + 35;
  429.     b[0].y2 = b[0].y1 + hgth;
  430.  
  431.     b[1].x2 = maxx - spcingx;
  432.     b[1].x1 = b[1].x2 - wdth;
  433.     b[1].y1 = spcingy + 35;
  434.     b[1].y2 = b[1].y1 + hgth;
  435.  
  436.     b[2].x2 = maxx - spcingx;
  437.     b[2].x1 = b[2].x2 - wdth;
  438.     b[2].y2 = maxy - spcingy;
  439.     b[2].y1 = b[2].y2 - hgth;
  440.  
  441.     b[3].x1 = spcingx;
  442.     b[3].x2 = b[3].x1 + wdth;
  443.     b[3].y2 = maxy - spcingy;
  444.     b[3].y1 = b[3].y2 - hgth;
  445.  
  446.     for(i=0;i<4;i++)
  447.         drwbox(1,15,b[i].x1++,b[i].y1++,b[i].x2--,b[i].y2--);
  448.  
  449.     ret = getkey();
  450.     if ((ret == 's') || (ret == 'q')) {
  451.         setview(0,0,maxx,maxy);
  452.         return(ret);
  453.     }
  454.     
  455.     /*
  456.      * Show the clipping
  457.      */
  458.     for(i=0;i<4;i++) {
  459.         setview(b[i].x1,b[i].y1,b[i].x2,b[i].y2);
  460.         fillview(i+10);
  461.     }
  462.  
  463.     setview(0,0,maxx,maxy);
  464.     ret = getkey();
  465.     if ((ret == 's') || (ret == 'q'))
  466.         return(ret);
  467.     
  468.     /*
  469.      * Set up windows and show area fill
  470.      */
  471.     fillscreen(0);
  472.     drwstring(1,7,0,title,10,0);
  473.     sprintf(buf,"fillarea(xseed,yseed,bordercolor,fillcolor);");
  474.     drwstring(1,7,0,buf,10,16);
  475.  
  476.     drwbox(1,15,5,35,maxx-4,maxy-4);
  477.     setview(6,36,maxx-5,maxy-5);
  478.  
  479.     colr=1;
  480.     for(i=0;i<=maxx/10;i++) {
  481.         x = 50 + randnum(maxx-50);
  482.         y = 50 + randnum(maxy-50);
  483.         radx = 2 + randnum(maxx/20);
  484.         rady = 2 + randnum(maxy/20);
  485.         drwellipse(1,colr++,x,y,radx,rady);
  486.         if (colr>10)
  487.             colr = 1;
  488.     }
  489.  
  490.     for(i=0;i<=maxx/15;i++) {
  491.         x = 50 + randnum(maxx-50);
  492.         y = 50 + randnum(maxy-50);
  493.         radx = 2 + randnum(maxx/20);
  494.         rady = 2 + randnum(maxy/20);
  495.         drwellipse(1,12,x,y,radx,rady);
  496.     }
  497.     
  498.     ret = getkey();
  499.     if ((ret == 's') || (ret == 'q')) {
  500.         setview(0,0,maxx,maxy);
  501.         return(ret);
  502.     }
  503.  
  504.     fillarea(7,37,12,10);
  505.     
  506.     setview(0,0,maxx,maxy);
  507.     ret = getkey();
  508.     if ((ret == 's') || (ret == 'q'))
  509.         return(ret);
  510.     
  511.     /*    
  512.      * Setup windows and show color fill
  513.      */
  514.     fillscreen(0);
  515.     drwstring(1,7,0,title,10,0);
  516.     sprintf(buf,"fillcolor(xseed,yseed,oldcolor,fillcolor);");
  517.     drwstring(1,7,0,buf,10,16);
  518.  
  519.     drwbox(1,15,5,35,maxx-4,maxy-4);
  520.     setview(6,36,maxx-5,maxy-5);
  521.  
  522.     colr=1;
  523.     for(i=0;i<=maxx/10;i++) {
  524.         x = 50 + randnum(maxx-50);
  525.         y = 50 + randnum(maxy-50);
  526.         radx = 2 + randnum(maxx/20);
  527.         rady = 2 + randnum(maxy/20);
  528.         drwellipse(1,colr++,x,y,radx,rady);
  529.         if (colr>10)
  530.             colr = 1;
  531.     }
  532.  
  533.     for(i=0;i<=maxx/15;i++) {
  534.         x = 50 + randnum(maxx-50);
  535.         y = 50 + randnum(maxy-50);
  536.         radx = 2 + randnum(maxx/20);
  537.         rady = 2 + randnum(maxy/20);
  538.         drwellipse(1,12,x,y,radx,rady);
  539.     }
  540.     
  541.     ret = getkey();
  542.     if ((ret == 's') || (ret == 'q')) {
  543.         setview(0,0,maxx,maxy);
  544.         return(ret);
  545.     }
  546.  
  547.     fillcolor(7,37,0,10);
  548.  
  549.     setview(0,0,maxx,maxy);
  550.  
  551.     ret = getkey();
  552.  
  553.     return(ret);
  554.     
  555. }
  556.  
  557.  
  558. /*********
  559.  * DOPAL *
  560.  *********/
  561.  
  562. char dopal(void)
  563. {
  564.     int x1, x2, y1, y2;
  565.     int i, colr;
  566.     char ret;
  567.     char title[TITLEN];
  568.     char buf[TITLEN];
  569.     
  570.     /*
  571.      * Set up the Title
  572.      */
  573.     sprintf(title,"DEMO 4: Palette functions");
  574.     palset(orgpal,0,255);
  575.  
  576.     /*
  577.      * Show palette set/get
  578.      */
  579.  
  580.     fillscreen(0);
  581.     setview(0,0,maxx,maxy);
  582.     drwstring(1,7,0,title,10,0);
  583.     sprintf(buf,"palget(pal,beg,end),palset(pal,beg,end)");
  584.     drwstring(1,7,0,buf,10,16);
  585.  
  586.     colr = 16;
  587.     x1 = 10;
  588.     x2 = maxx - 9;
  589.     y1 = 35;
  590.     y2 = maxy - 9;
  591.     i = 0;
  592.     while (y1+i < y2-i) {
  593.         drwbox(1,colr++,x1+i,y1+i,x2-i,y2-i);
  594.         if (colr>255)
  595.             colr = 16;
  596.         i++;
  597.     }
  598.     ret = getkey();
  599.     if ((ret == 's') || (ret == 'q')) {
  600.         fillscreen(0);
  601.         setview(0,0,maxx,maxy);
  602.         return(ret);
  603.     }
  604.     palset(pal,16,255);
  605.     ret = getkey();
  606.     if ((ret == 's') || (ret == 'q')) {
  607.         setview(0,0,maxx,maxy);
  608.         fillscreen(0);
  609.         return(ret);
  610.     }
  611.  
  612.     /*
  613.      * Show palette auto fade out/in
  614.      */
  615.     setview(0,16,maxx,32);
  616.     fillview(0);
  617.     sprintf(buf,"palioauto(pal,beg,end,speed);");
  618.     drwstring(1,7,0,buf,10,16);
  619.     palioauto(pal,16,255,-2);
  620.     palioauto(pal,16,255,2);
  621.     ret = getkey();
  622.     if ((ret == 's') || (ret == 'q')) {
  623.         setview(0,0,maxx,maxy);
  624.         return(ret);
  625.     }
  626.  
  627.     /*
  628.      * Show palette auto fade to
  629.      */
  630.     setview(0,16,maxx,32);
  631.     fillview(0);
  632.     sprintf(buf,"palchgauto(pal,newpal,beg,end,speed);");
  633.     drwstring(1,7,0,buf,10,16);
  634.     palchgauto(pal,pal2,16,255,2);
  635.     palchgauto(pal2,pal,16,255,2);
  636.     ret = getkey();
  637.     if ((ret == 's') || (ret == 'q')) {
  638.         setview(0,0,maxx,maxy);
  639.         return(ret);
  640.     }
  641.  
  642.     /*
  643.      * Show palette rotate
  644.      */
  645.     setview(0,16,maxx,32);
  646.     fillview(0);
  647.     sprintf(buf,"palrotate(pal,beg,end,shift);");
  648.     drwstring(1,7,0,buf,10,16);
  649.     for(i=0;i<=240;i++) {
  650.         palrotate(pal,16,255,2);
  651.         palget(pal,16,255);
  652.     }
  653.     for(i=0;i<=120;i++) {
  654.         palrotate(pal,16,255,-8);
  655.         palget(pal,16,255);
  656.     }
  657.     ret = getkey();
  658.     if ((ret == 's') || (ret == 'q'))
  659.         setview(0,0,maxx,maxy);
  660.  
  661.     return(ret);
  662.  
  663. }
  664.  
  665.  
  666. /***********
  667.  * DOPRIMS *
  668.  ***********/
  669.  
  670. char doprims(void)
  671. {
  672.     int x1, x2, y1, y2;
  673.     int maxrad, radx, rady;
  674.     int i, colr, num;
  675.     char ret;
  676.     char title[TITLEN];
  677.     char buf[TITLEN];
  678.     
  679.     /*
  680.      * Set up the Title
  681.      */
  682.     sprintf(title,"DEMO 1: Primitives");
  683.     palset(orgpal,0,255);
  684.  
  685.     /*
  686.      * Draw some points
  687.      */
  688.  
  689.     fillscreen(0);
  690.     setview(0,0,maxx,maxy);
  691.     drwstring(1,7,0,title,10,0);
  692.     sprintf(buf,"drwpoint(mode,color,x,y);");
  693.     drwstring(1,7,0,buf,10,16);
  694.     setview(0,32,maxx,maxy);
  695.     colr = 1;
  696.     num = maxx * 2;
  697.     for(i=0;i<num;i++) {
  698.         x1 = randnum(maxx);
  699.         y1 = randnum(maxy);
  700.         drwpoint(1,colr++,x1,y1);
  701.         if (colr>15)
  702.             colr = 1;
  703.     }   
  704.     setview(0,0,maxx,maxy);
  705.     ret = getkey();
  706.     if ((ret=='s') || (ret=='q'))
  707.         return(ret);
  708.     
  709.     /*
  710.      * Draw some lines
  711.      */
  712.     fillscreen(0);
  713.     setview(0,0,maxx,maxy);
  714.     drwstring(1,7,0,title,10,0);
  715.     sprintf(buf,"drwline(mode,color,x1,y1,x2,y2);");
  716.     drwstring(1,7,0,buf,10,16);
  717.     setview(0,32,maxx,maxy);
  718.     colr = 1;
  719.     num = maxx / 6;
  720.     for(i=0;i<num;i++) {
  721.         x1 = randnum(maxx);
  722.         y1 = randnum(maxy);
  723.         x2 = randnum(maxx);
  724.         y2 = randnum(maxy);
  725.         drwline(1,colr++,x1,y1,x2,y2);
  726.         if (colr>15)
  727.             colr = 1;
  728.     }   
  729.     setview(0,0,maxx,maxy);
  730.     ret = getkey();
  731.     if ((ret=='s') || (ret=='q'))
  732.         return(ret);
  733.  
  734.     /*
  735.      * Draw some boxes
  736.      */
  737.     fillscreen(0);
  738.     setview(0,0,maxx,maxy);
  739.     drwstring(1,7,0,title,10,0);
  740.     sprintf(buf,"drwbox(mode,color,x1,y1,x2,y2);");
  741.     drwstring(1,7,0,buf,10,16);
  742.     setview(0,32,maxx,maxy);
  743.     colr = 1;
  744.     num = maxx / 10;
  745.     for(i=0;i<num;i++) {
  746.         x1 = randnum(maxx);
  747.         y1 = randnum(maxy);
  748.         x2 = randnum(maxx);
  749.         y2 = randnum(maxy);
  750.         drwbox(1,colr++,x1,y1,x2,y2);
  751.         if (colr>15)
  752.             colr = 1;
  753.     }   
  754.     setview(0,0,maxx,maxy);
  755.     ret = getkey();
  756.     if ((ret=='s') || (ret=='q'))
  757.         return(ret);
  758.  
  759.     /*
  760.      * Draw some circles
  761.      */
  762.     fillscreen(0);
  763.     setview(0,0,maxx,maxy);
  764.     drwstring(1,7,0,title,10,0);
  765.     sprintf(buf,"drwcircle(mode,color,cx,cy,radius);");
  766.     drwstring(1,7,0,buf,10,16);
  767.     setview(0,32,maxx,maxy);
  768.     colr = 1;
  769.     num = maxx / 20;
  770.     maxrad = maxx / 2;
  771.     for(i=0;i<num;i++) {
  772.         x1 = randnum(maxx);
  773.         y1 = randnum(maxy);
  774.         radx = randnum(maxrad);
  775.         drwcircle(1,colr++,x1,y1,radx);
  776.         if (colr>15)
  777.             colr = 1;
  778.     }   
  779.     setview(0,0,maxx,maxy);
  780.     ret = getkey();
  781.     if ((ret=='s') || (ret=='q'))
  782.         return(ret);
  783.  
  784.     /*
  785.      * Draw some ellipses
  786.      */
  787.     fillscreen(0);
  788.     setview(0,0,maxx,maxy);
  789.     drwstring(1,7,0,title,10,0);
  790.     sprintf(buf,"drwellipse(mode,color,cx,cy,radiusx,radiusy);");
  791.     drwstring(1,7,0,buf,10,16);
  792.     setview(0,32,maxx,maxy);
  793.     colr = 1;
  794.     num = maxx / 20;
  795.     maxrad = maxx / 2;
  796.     for(i=0;i<num;i++) {
  797.         x1 = randnum(maxx);
  798.         y1 = randnum(maxy);
  799.         radx = randnum(maxrad);
  800.         rady = randnum(maxrad);
  801.         drwellipse(1,colr++,x1,y1,radx,rady);
  802.         if (colr>15)
  803.             colr = 1;
  804.     }   
  805.     setview(0,0,maxx,maxy);
  806.  
  807.     ret = getkey();
  808.  
  809.     return(ret);
  810.  
  811. }
  812.  
  813.  
  814. /************
  815.  * DOSCROLL *
  816.  ************/
  817.  
  818. char doscroll(void)
  819. {
  820.     int i, colr, num, totnum;
  821.     int a, b, c, d;
  822.     int x1, x2, y1, y2;
  823.     int spcing, skip;
  824.     char ret;
  825.     char title[TITLEN];
  826.     char buf[TITLEN];
  827.     char buf2[TITLEN];
  828.     
  829.     /*
  830.      * Set up the Title
  831.      */
  832.     sprintf(title,"DEMO 7: Scroll functions");
  833.     palset(pal,0,255);
  834.     fillscreen(0);
  835.     setview(0,0,maxx,maxy);
  836.     drwstring(1,7,0,title,10,0);
  837.     
  838.     spcing = (maxy - 32) / 5;
  839.     skip = (int)(((float)maxx + 1.) / 320. + .9) * 2 - 1;
  840.     num = spcing / 2 / skip;
  841.     if (spcing / 2 != (float)spcing / 2.)
  842.         spcing++;
  843.     x1 = (maxx + 1) / 2 - spcing;
  844.     y1 = (maxy + 1 - 32) / 2 + 32 - spcing;
  845.     x2 = (maxx + 1) / 2 + spcing;
  846.     y2 = (maxy + 1 - 32) / 2 + 32 + spcing;
  847.  
  848.     drwbox(1,12,x1++,y1++,x2--,y2--);
  849.     colr = 16;
  850.     sprintf(buf2,"TEXT text TEXT");
  851.  
  852.     /*
  853.      * Show scrollup
  854.      */
  855.     setview(0,16,maxx,maxy);
  856.     sprintf(buf,"scrollup(x1,y1,x2,y2,numlines,fillcolor);");
  857.     drwstring(1,7,0,buf,10,16);
  858.     setview(x1,y1,x2,y2);
  859.     fillview(0);
  860.     totnum = maxx / 10;
  861.     for(i=0;i<totnum;i++) {
  862.         a = randnum(maxx);
  863.         b = randnum(maxy);
  864.         c = randnum(maxx);
  865.         d = randnum(maxy);
  866.         drwline(1,colr,a,b,c,d);
  867.         colr += 3;
  868.         if (colr > 255)
  869.             colr = 16;
  870.     }
  871.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  872.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  873.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  874.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  875.  
  876.     ret = getkey();
  877.     if ((ret=='s') || (ret=='q'))
  878.         return(ret);
  879.  
  880.     for(i=0;i<num;i++)
  881.         scrollup(x1,y1,x2,y2,skip,0);
  882.  
  883.     ret = getkey();
  884.     if ((ret=='s') || (ret=='q'))
  885.         return(ret);
  886.  
  887.     /*
  888.      * Show scrolllt
  889.      */
  890.     setview(0,16,maxx,maxy);
  891.     sprintf(buf,"scrolllt(x1,y1,x2,y2,numlines,fillcolor);");
  892.     drwstring(1,7,0,buf,10,16);
  893.     setview(x1,y1,x2,y2);
  894.     fillview(0);
  895.     totnum = maxx / 10;
  896.     for(i=0;i<totnum;i++) {
  897.         a = randnum(maxx);
  898.         b = randnum(maxy);
  899.         c = randnum(maxx);
  900.         d = randnum(maxy);
  901.         drwline(1,colr,a,b,c,d);
  902.         colr += 3;
  903.         if (colr > 255)
  904.             colr = 16;
  905.     }
  906.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  907.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  908.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  909.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  910.  
  911.     ret = getkey();
  912.     if ((ret=='s') || (ret=='q'))
  913.         return(ret);
  914.  
  915.     for(i=0;i<num;i++)
  916.         scrolllt(x1,y1,x2,y2,skip,0);
  917.  
  918.     ret = getkey();
  919.     if ((ret=='s') || (ret=='q'))
  920.         return(ret);
  921.  
  922.     /*
  923.      * Show scrolldn
  924.      */
  925.     setview(0,16,maxx,maxy);
  926.     sprintf(buf,"scrolldn(x1,y1,x2,y2,numlines,fillcolor);");
  927.     drwstring(1,7,0,buf,10,16);
  928.     setview(x1,y1,x2,y2);
  929.     fillview(0);
  930.     totnum = maxx / 10;
  931.     for(i=0;i<totnum;i++) {
  932.         a = randnum(maxx);
  933.         b = randnum(maxy);
  934.         c = randnum(maxx);
  935.         d = randnum(maxy);
  936.         drwline(1,colr,a,b,c,d);
  937.         colr += 3;
  938.         if (colr > 255)
  939.             colr = 16;
  940.     }
  941.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  942.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  943.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  944.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  945.  
  946.     ret = getkey();
  947.     if ((ret=='s') || (ret=='q'))
  948.         return(ret);
  949.  
  950.     for(i=0;i<num;i++)
  951.         scrolldn(x1,y1,x2,y2,skip,0);
  952.  
  953.     ret = getkey();
  954.     if ((ret=='s') || (ret=='q'))
  955.         return(ret);
  956.  
  957.     /*
  958.      * Show scrollrt
  959.      */
  960.     setview(0,16,maxx,maxy);
  961.     sprintf(buf,"scrollrt(x1,y1,x2,y2,numlines,fillcolor);");
  962.     drwstring(1,7,0,buf,10,16);
  963.     setview(x1,y1,x2,y2);
  964.     fillview(0);
  965.     totnum = maxx / 10;
  966.     for(i=0;i<totnum;i++) {
  967.         a = randnum(maxx);
  968.         b = randnum(maxy);
  969.         c = randnum(maxx);
  970.         d = randnum(maxy);
  971.         drwline(1,colr,a,b,c,d);
  972.         colr += 3;
  973.         if (colr > 255)
  974.             colr = 16;
  975.     }
  976.     drwstring(1,7,0,buf2,x1+spcing,y1+spcing);
  977.     drwstringlt(1,7,0,buf2,x1+spcing,y1+spcing);
  978.     drwstringrt(1,7,0,buf2,x1+spcing,y1+spcing);
  979.     drwstringdn(1,7,0,buf2,x1+spcing,y1+spcing);
  980.  
  981.     ret = getkey();
  982.     if ((ret=='s') || (ret=='q'))
  983.         return(ret);
  984.  
  985.     for(i=0;i<num;i++)
  986.         scrollrt(x1,y1,x2,y2,skip,0);
  987.  
  988.     ret = getkey();
  989.  
  990.     return(ret);
  991.  
  992. }
  993.  
  994.  
  995. /**********
  996.  * DOTEXT *
  997.  **********/
  998.  
  999. char dotext(void)
  1000. {
  1001.     int i, colr;
  1002.     char ret;
  1003.     char title[TITLEN];
  1004.     char buf[TITLEN];
  1005.     char buf2[TITLEN];
  1006.  
  1007.     /*
  1008.      * Set up the Title
  1009.      */
  1010.     sprintf(title,"DEMO 6: Text functions");
  1011.     palset(pal,0,255);
  1012.  
  1013.     /*
  1014.      * Show alternate print directions
  1015.      */
  1016.     fillscreen(0);
  1017.     setview(0,0,maxx,maxy);
  1018.     drwstring(1,7,0,title,10,0);
  1019.     sprintf(buf,"drwstring(mode,foregnd,bkgnd,string,x,y);");
  1020.     drwstring(1,7,0,buf,10,16);
  1021.     setview(0,32,maxx,maxy);
  1022.     sprintf(buf2,"The Quick Brown Fox Jumped Over The Lazy Dog's Back! 0123456789");
  1023.     colr = 16;
  1024.     for(i=32;i<=maxy;i+=20) {
  1025.         drwstring(1,colr,0,buf2,0,i);
  1026.         colr+=5;
  1027.         if (colr>255)
  1028.             colr = 16;
  1029.     }
  1030.     ret = getkey();
  1031.     if ((ret=='s') || (ret=='q')) {
  1032.         setview(0,0,maxx,maxy);
  1033.         fillscreen(0);
  1034.         return(ret);
  1035.     }
  1036.  
  1037.     fillview(0);
  1038.     setview(0,16,maxx,32);
  1039.     sprintf(buf,"drwstringlt(mode,foregnd,bkgnd,string,x,y);");
  1040.     drwstring(1,7,0,buf,10,16);
  1041.     setview(0,32,maxx,maxy);
  1042.     colr = 16;
  1043.     for(i=0;i<=maxx;i+=20) {
  1044.         drwstringlt(1,colr,0,buf2,i,maxy);
  1045.         colr+=5;
  1046.         if (colr>255)
  1047.             colr = 16;
  1048.     }
  1049.     ret = getkey();
  1050.     if ((ret=='s') || (ret=='q')) {
  1051.         setview(0,0,maxx,maxy);
  1052.         fillscreen(0);
  1053.         return(ret);
  1054.     }
  1055.  
  1056.     fillview(0);
  1057.     setview(0,16,maxx,32);
  1058.     sprintf(buf,"drwstringdn(mode,foregnd,bkgnd,string,x,y);");
  1059.     drwstring(1,7,0,buf,10,16);
  1060.     setview(0,32,maxx,maxy);
  1061.     colr = 16;
  1062.     for(i=maxy;i>=32;i-=20) {
  1063.         drwstringdn(1,colr,0,buf2,maxx,i);
  1064.         colr+=5;
  1065.         if (colr>255)
  1066.             colr = 16;
  1067.     }
  1068.     ret = getkey();
  1069.     if ((ret=='s') || (ret=='q')) {
  1070.         setview(0,0,maxx,maxy);
  1071.         fillscreen(0);
  1072.         return(ret);
  1073.     }
  1074.  
  1075.     fillview(0);
  1076.     setview(0,16,maxx,32);
  1077.     sprintf(buf,"drwstringrt(mode,foregnd,bkgnd,string,x,y);");
  1078.     drwstring(1,7,0,buf,10,16);
  1079.     setview(0,32,maxx,maxy);
  1080.     colr = 16;
  1081.     for(i=maxx;i>=0;i-=20) {
  1082.         drwstringrt(1,colr,0,buf2,i,32);
  1083.         colr+=5;
  1084.         if (colr>255)
  1085.             colr = 16;
  1086.     }
  1087.     ret = getkey();
  1088.     setview(0,0,maxx,maxy);
  1089.     fillscreen(0);
  1090.  
  1091.     return(ret);
  1092.  
  1093. }
  1094.